package com.kisszpy.system.actions;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.management.relation.RoleStatus;

import net.sf.json.JSONArray;
import net.sf.json.JSONFunction;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.PropertyFilter;

import com.kisszpy.core.BaseAction;
import com.kisszpy.core.utils.CaptchaCode;
import com.kisszpy.system.entity.SysRole;
import com.kisszpy.system.entity.SysUser;
import com.kisszpy.system.service.SysUserService;

public class SysMenuAction extends BaseAction{

	private static final long serialVersionUID = 4398561091945690778L;

	private SysUserService sysUserService;
	private SysUser sysUser = new SysUser();
	private String code;
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public SysUser getSysUser() {
		return sysUser;
	}
	public void setSysUser(SysUser sysUser) {
		this.sysUser = sysUser;
	}
	public void setSysUserService(SysUserService sysUserService) {
		this.sysUserService = sysUserService;
	}
	public String login() throws Exception {
		SysUser user = this.sysUserService.login(sysUser);
		if(null!=user){
			if(this.code.equalsIgnoreCase(session.get("code").toString())){ // 验证码校验
				session.put("login_key", user);
				return "login_success";
			}
		}
		return "login_ui";
	}
	/*JsonConfig config = new JsonConfig();
	config.setJsonPropertyFilter(new PropertyFilter() {
		public boolean apply(Object arg0, String arg1, Object arg2) {
			if("roleSet".equals(arg1)||"menuSet".equals(arg1)){
				return true;
			}
			return false;
		}
	});*/
	public String loadLoginInfo(){
		SysUser user = (SysUser) session.get("login_key");
		JSONObject json = JSONObject.fromObject(user);
		renderJSON(json.toString());
		return null;
	};
	public String logOff() throws Exception {
		System.out.println("logOff");
		return super.execute();
	}
	public String renderCode() throws Exception {
		System.out.println(this.sysUserService);
		CaptchaCode.build(request, response);
		return null;
	}
}
